package org.example;

import java.util.HashMap;
import java.util.Map;

public class Test5 {
    //leetcode 454 四数相加II https://leetcode.cn/problems/4sum-ii/description/
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer,Integer> hash = new HashMap<>();
        for (int i = 0; i < nums1.length; i++) {
            for (int j = 0; j < nums2.length; j++) {
                int in = nums1[i] + nums2[j];
                hash.put(in,hash.getOrDefault(in,0) + 1);
            }
        }
        int ret = 0;
        for (int i = 0; i < nums3.length; i++) {
            for (int j = 0; j < nums4.length; j++) {
                ret += hash.getOrDefault(0 - nums3[i] - nums4[j], 0);
            }
        }
        return ret;
    }
}
